#use Test::More tests => 44;
use Test::More qw(no_plan);

BEGIN {
use_ok( 'Firepear::Carrot::DOM' );
}
exit;

# setup
my $d;
my $attrs;
my $tiefile = './t/corpus/test';

# bad restore
$d = Firepear::Carrot::DOM->new( attach => 'x/fnord.txt');
is ($d->status, 905, 'restore from unreadable file');

# other bad restore
rename './t/corpus/test.dom', './t/corpus/test.savedom';
$d = Firepear::Carrot::DOM->new( attach => $tiefile );
is ($d->status, 904, 'Storable cant restore');
rename './t/corpus/test.savedom', './t/corpus/test.dom';

# test returns from routine calls while status is nonzero, while we're here
is ($d->add, undef, 'status');
is ($d->nodeattrs, undef, 'status');
is ($d->nodechildren, undef, 'status');
is ($d->nodecontent, undef, 'status');
is ($d->nodename, undef, 'status');
is ($d->nodeid, undef, 'status');
is ($d->nodeparent, undef, 'status');
is ($d->nodefileinfo, undef, 'status');

# restore the object using saved data
$d = Firepear::Carrot::DOM->new( attach => $tiefile );
# is everything where we left it?
is ($#{ $d->{dom}{tree} }, 6, 'nodecount was saved and restored properly');
is ($d->add({ type => 'VERBATIM', element => 'code', => finfo => [2, 10] }),
    7, 'new VERB node');
is ($d->status, 0, 'restore from unreadable file');
is_deeply ($d->nodechildren, [1, 2, 3, 7], 'roots kids');

#
# Devel::Cover catches
#

# attempt to re-add content to a text node
is ($d->nodecontent(1), 'First node', 'original text node');
is ($d->nodecontent(1, 'foo'), undef, 'cant re-set content');
is ($d->status, 404, 'cant re-set content');
$d->status(0);
# nodename catching invalid nodeids
is ($d->nodename(73), undef, 'invalid id');
is ($d->status, 301, 'invalid node');
$d->status(0);
# try to redeclare node element name
is ($d->nodename(0), 'document', 'root');
is ($d->nodename(0, 'foo'), undef, 'cant re-set element name');
is ($d->status, 404, 'cant re-set name');
$d->status(0);
# some nodeid testing
$d->jmp(3);
is ($d->nodeid, 'sec1', 'retrieved');
is ($d->nodeid(3,'foo'), undef, 'cant change identifier');
is ($d->status, 404, 'cant change identifier');
$d->status(0);
is ($d->nodeid(73), undef, 'invalid id');
is ($d->status, 301, 'invalid node');
$d->status(0);
is ($d->nodeid(4), undef, 'no id');
is ($d->status, 306, 'no id');
$d->status(0);
# nodefileinfo tests
is ($d->nodefileinfo(73), undef, 'invalid id');
is ($d->status, 301, 'invalid node');
$d->status(0);
$d->jmp(1);
is_deeply ($d->nodefileinfo, [0,1], 'declared node');
is ($d->status, 0, 'ok');
$d->status(0);
# validnode
is ($d->validnode, undef, 'is WHAT valid?');
# nodechildren
is ($d->nodechildren(1,73), undef, 'this shouldnt work');
is ($d->status, 301, 'invalid node');
#is_deeply ($d->nodechildren(1), [0,7], 'ok');
$d->status(0);
#is ($d->nodechildren(1,[3,4,5]), 1, 'adding listref seems to work');
#is_deeply ($d->nodechildren(1), [0,7,3,4,5], 'yep');
# nukenode
$d->nukenode(3);
is ($d->nodecontent(1), 'First node', 'original text node');
is ($d->{dom}{text}[0], 'First node', 'same thing');
$d->nukenode(1);

# now clean up
$d->detach( mode => 'discard');
is ((-e "$tiefile"),     undef, 'DB file gone');
is ((-e "$tiefile.dom"), undef, 'DOM file gone');
